package com.scuthnweb.tool;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;

public class SystemContants {
	public static String path = null;
	
	public static String getProperty(String pname) throws IOException{
		ActionContext ctx = ActionContext.getContext();
		ServletContext sc = (ServletContext) ctx.get(ServletActionContext.SERVLET_CONTEXT);
		Properties pps = new Properties();
		File directory = new File("/");
		InputStream in = new BufferedInputStream (new FileInputStream(directory.getAbsolutePath()+File.separator+"SystemContants.properties"));  
		pps.load(in);
		String value = pps.getProperty(pname);
		return value;
	}
	
	public static String getValidate_code_img_prefix_path(){
		if(path==null){
			ActionContext ctx = ActionContext.getContext();
			ServletContext sc = (ServletContext) ctx.get(ServletActionContext.SERVLET_CONTEXT);
		    path = String.copyValueOf(sc.getRealPath("/").toCharArray())+"validate_code_img";
		}
		return path;
	}
}
